package me.magicall.test.img;

import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class ApplicationFrame extends Frame {
	public ApplicationFrame() {
		this("ApplicationFrame v1.0");
	}

	public ApplicationFrame(final String title) {
		super(title);
		createUI();
	}

	protected void createUI() {
		setSize(500, 400);
		center();

		addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(final WindowEvent e) {
				dispose();
				System.exit(0);
			}
		});
	}

	public void center() {
		final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		final Dimension frameSize = getSize();
		final int x = (screenSize.width - frameSize.width) / 2;
		final int y = (screenSize.height - frameSize.height) / 2;
		setLocation(x, y);
	}
}